#!/usr/bin/perl
#alert_setting.cgi

require './mdmjobs-lib.pl';
&ReadParse();

&header($text{'alert_detail'}, "", "index", 0, 1,undef,undef);

if (!(-f $config{'alertdir'})){
	`mkdir -p $config{'alertdir'}`;
}

my @servers=&foreign_call("mdmsearch","list_controlledservs");
my $listaddr=&get_alertinfo;
my %alertinfo;
$alertinfo{'list'}->{'have'}='no';
%alertinfo=%$listaddr;

if ($alertinfo{'list'}->{'have'} ne 'yes'){
	print "$text{'index_noalert'}\n";
	
}else{
	print "<table class=mode1 border=0 cellpadding=4 cellspacing=1 width=100%>\n";	
	print "<tr class=title1>\n";
	print "<td><b>$text{'index_systemid'}</b></td>\n";
	print "<td><b>$text{'index_hostname'}</b></td>\n";
	print "<td><b>$text{'index_ip'}</b></td>\n";
	print "<td><b>$text{'index_mesg1'}</b></td>\n";	
	print "<td><b>$text{'index_mesg0'}</b></td></tr>\n";
	foreach $s (@servers) {
		if ($alertinfo{"$s->{id}"}->{'status'}){
			if ($mode eq 'mode1'){
				$mode='mode2';
			}else{
				$mode='mode1';
			}
			print "<tr class=$mode>\n";
			print "<td>$s->{'id'}</td>\n";
			print "<td>$s->{'hostname'}</td>\n";	
			print "<td>$s->{'ip'}</td>\n";
			local $downfile1=$s->{'id'}.".mesg1";
			local $downfile0=$s->{'id'}.".mesg0";
			if ($alertinfo{"$s->{id}"}->{'mesg1'}){
				local $mesg1file=$config{'alertdir'}.$s->{'id'}.".mesg1";
				unlink($downfile1) if(-e $downfile1);
				symlink("$mesg1file",$downfile1);
				print "<td><a href=$downfile1><img border=0 src=../images/text.gif></a>&nbsp;$downfile1</td>\n"
			}else{
				print "<td>&nbsp;</td>\n"
			}
						
			if ($alertinfo{"$s->{id}"}->{'mesg0'}){
				local $mesg0file=$config{'alertdir'}.$s->{'id'}.".mesg0"; 
				unlink($downfile0) if(-e $downfile0);
				symlink("$mesg0file",$downfile0);
				print "<td><a href=$downfile0><img border=0 src=../images/text.gif></a>&nbsp;$downfile0</td>\n"
			}else{
				print "<td>&nbsp;</td>\n"
			}
			
			print"</tr>\n";
		}
	}
	print "</table>";	
}

print "<table class=mode1 border=0 cellpadding=4 cellspacing=1 width=100%>\n";
print "<hr>\n";	
print "<form action=mdm_alert.cgi>\n";
print "<tr><td><input type=submit class=button value=\"$text{'submit_getalert'}\"\n";
print "</form></table>";	

&footer("index.cgi",$text{'index'});